home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-21 | 2.8 KB | 104 lines | [TEXT/KAHL] |
- // this is a routine to return a compressed pict from a pixmap
- //
- // Nick Thompson, June '94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
-
- #include <Types.h>
- #include <Traps.h>
- #include <Memory.h>
- #include <Errors.h>
- #include <FixMath.h>
- #include "Movies.h"
- #include "ImageCompression.h"
- #include "QuickTimeComponents.h"
-
- #include "GetQTCompressedPict.h"
-
- //---------------------------------------------------------------------------------------
- // return a compressed pict from a pixmap
-
- PicHandle GetQTCompressedPict( PixMapHandle myPixMap, SCParams *params )
- {
- long maxCompressedSize = 0;
- Handle compressedDataH = nil;
- Ptr compressedDataP;
- ImageDescriptionHandle imageDescH = nil;
- OSErr theErr;
- PicHandle myPic = nil;
- Rect bounds = (**myPixMap).bounds;
- CodecType theCodecType = 'jpeg';
- CodecComponent theCodec = (CodecComponent)anyCodec;
- CodecQ spatialQuality = codecNormalQuality;
- short depth = 0; /* let ICM choose depth */
-
- theErr = GetMaxCompressionSize( myPixMap,
- &bounds,
- params->depth, // pixel depth to compress image at
- params->spatialQuality, // spatial quality to compress image at
- params->theCodecType, // type of codec to use 'jpeg','rpza', etc.
- params->theCodec, // codec to use either in general
- // terms (bestSpeed, bestFidelity,etc.)
- &maxCompressedSize);
-
- CheckError( theErr, "\pError in GetMaxCompressionSize") ;
-
- if ( theErr ) return nil;
-
- imageDescH = (ImageDescriptionHandle)NewHandle(4);
-
- compressedDataH = NewHandle(maxCompressedSize);
-
- if ( compressedDataH != nil && imageDescH != nil )
- {
- MoveHHi(compressedDataH);
- HLock(compressedDataH);
- compressedDataP = StripAddress(*compressedDataH);
-
- theErr = CompressImage( myPixMap,
- &bounds,
- params->spatialQuality,
- params->theCodecType,
- imageDescH,
- compressedDataP );
-
-
- CheckError( theErr, "\pError in CompressImage") ;
-
-
- if ( theErr == noErr )
- {
- OpenCPicParams myOpenCPicparams ;
-
- myOpenCPicparams.srcRect = bounds ;
- myOpenCPicparams.hRes = (**imageDescH).hRes ;
- myOpenCPicparams.vRes = (**imageDescH).vRes ;
- myOpenCPicparams.version = -2 ;
-
- ClipRect(&bounds);
-
- myPic = OpenCPicture(&myOpenCPicparams);
- theErr = DecompressImage( compressedDataP,
- imageDescH,
- myPixMap,
- &bounds,
- &bounds,
- srcCopy,
- nil );
-
- CheckError( theErr, "\pError in DecompressImage") ;
-
- ClosePicture();
- }
- if ( theErr != noErr || GetHandleSize((Handle)myPic) == sizeof(Picture) )
- {
- KillPicture(myPic);
- myPic = nil;
- }
- }
- if (imageDescH) DisposeHandle( (Handle)imageDescH);
- if (compressedDataH) DisposeHandle( compressedDataH);
-
- return myPic;
- }